<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<jsp:include page="/jsp/admin/common.jsp" />
<jsp:include page="/jsp/formHead.jsp" />
<script type="text/javascript">
//页面初始化
$().ready(function(){

	//初始化操作员关联的角色信息
	var selected = [${selected }];

	for(var i=0, len=selected.length; i<len; i++){

		$("input[type='checkbox'][value='" + selected[i] + "']").attr("checked", true);
	}

	//后退按钮事件
	$("#backButton").click(function(){
		location.href = basePath + "jsp/admin/setting/admin_list.jsp";
	});

	//表单验证
	$("#form_add").validate({
		rules: {
			username : {
				required: true,
				pattern : /^[0-9a-z_A-Z\u4e00-\u9fa5]+$/,
				minlength: 2,
				maxlength: 16,
				remote: 
				{ 
					url: "<%=basePath%>admin/check_username.do", 
					cache: false 
				}
			},
			password: {
				required: true,
				pattern: /^[^\s&\"<>]+$/,
				minlength: 4,
				maxlength: 20
			},
			rePassword: {
				required: true,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true
			},
			tel: {
				isPhone: true
			}
		},
		messages: {
			username: {
				pattern: "非法字符",
				remote: "用户名被禁用或已存在"
			},
			password: {
				pattern: "非法字符"
			}
			,email: {
				remote: "已存在"
			}
		}
	});

	//判断是否是编辑状态
	var in_edit = ${!empty entity.id};
	
	if(in_edit){
		$("input[name='username']").attr("disabled", "disabled");
		$("div.path").append("<span>管理员修改</span>");
	} else {
		$("div.path").append("<span>管理员创建</span>");
	}
});
</script>
</head>
<body>
	<div class="path">
		<a href="">首页</a> &raquo; 
	</div>
	<form id="form_add" action="<%=basePath %>admin/admin_save.do" method="post">
		<table class="input tabContent">
			<tr>
				<th>
					<span class="requiredField">*</span>用户名:
				</th>
				<td>
					<input type="hidden" name="id" value="${entity.id }" />
					<input type="text" name="username" class="text" maxlength="200" value="${entity.username }"/>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>密码:
				</th>
				<td>
					<input type="password" id="password" name="password" class="text" maxlength="200" value="${entity.password }"/>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>确认密码:
				</th>
				<td>
					<input type="password" name="rePassword" class="text" maxlength="200" value="${entity.password }"/>
				</td>
			</tr>
			<tr>
				<th>
					姓名:
				</th>
				<td>
					<input type="text" name="name" class="text" maxlength="200" value="${entity.name }"/>
				</td>
			</tr>
			<tr>
				<th>
					联系方式:
				</th>
				<td>
					<input type="text" name="tel" class="text" maxlength="200" value="${entity.tel }"/>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>E-mail:
				</th>
				<td>
					<input type="text" name="email" class="text" maxlength="200" value="${entity.email }"/>
				</td>
			</tr>
			<tr>
				<th>
					角色:
				</th>
				<td>
					<span class="fieldSet">
					<c:forEach var="role" items="${roleList }">
						<label>
							<input type="checkbox" name="roleIds" value="${role.id }"/>${role.name }
						</label>
					</c:forEach>
					</span>
					
				</td>
			</tr>
			<tr>
				<th>
					设置:
				</th>
				<td>
					<label>
						<input type="checkbox" name="status" value="U" checked="checked"/>启用
					</label>
				</td>
			</tr>
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<input type="submit" class="button" value="确定" />
					<input type="button" id="backButton" class="button" value="返回"/>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>